package com.example.mytayunapi.Mapper;

import com.example.mytayunapi.Entity.commentInfo;
import com.example.mytayunapi.Vo.UserCommentOrder;
import com.example.mytayunapi.Vo.UserOrderCommentOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface commentInfoMapper {
    @Select("SELECT c.*,u.Nick_name,o.Product_id,o.order_time,o.Order_status FROM comment c JOIN user u ON c.School_degree = u.School_degree JOIN orders o ON c.order_id = o.order_id")
    List<UserCommentOrder> getOrderUserComment();

    @Select("SELECT c.*,u.Nick_name,o.Product_id,o.order_time,o.Order_status FROM comment c JOIN user u ON c.School_degree = u.School_degree JOIN orders o ON c.order_id = o.order_id WHERE Comment_id like #{Comment_id}")
    List<UserCommentOrder> getCommentUserOrderId(Integer Comment_id);

    @Update("update comment set Comment_status = #{Comment_status},beizhu = #{beizhu},operator = #{operator} where Comment_id = #{Comment_id}")
    Integer updateCommentInfoByOrderId(UserCommentOrder commentStatusInfo);

    @Select("SELECT c.*,u.Nick_name,o.Product_id,o.order_time,o.Order_status FROM comment c JOIN user u ON c.School_degree = u.School_degree JOIN orders o ON c.order_id = o.order_id where Comment_status = #{Comment_status}")
    List<UserCommentOrder> getCommentUserOrderStatus(String Comment_status);

    @Select("SELECT c.*,u.Nick_name,o.Product_id,o.order_time,o.Order_status FROM comment c JOIN user u ON c.School_degree = u.School_degree JOIN orders o ON c.order_id = o.order_id where Comment_status != #{Comment_status}")
    List<UserCommentOrder> getCommentUserOrderStatusNa(String Comment_status);

    @Select("SELECT c.*,u.Nick_name,o.Product_id,o.order_time,o.Order_status FROM comment c JOIN user u ON c.School_degree = u.School_degree JOIN orders o ON c.order_id = o.order_id where Comment_content LIKE CONCAT('%',#{keyword},'%') and Comment_rank = #{Comment_rank} and Comment_status = '审核中'")
    List<UserCommentOrder> getCommentcontentArank(@Param("keyword") String keyword, @Param("Comment_rank") String Comment_rank);

    @Select("SELECT c.*,u.Nick_name,o.Product_id,o.order_time,o.Order_status FROM comment c JOIN user u ON c.School_degree = u.School_degree JOIN orders o ON c.order_id = o.order_id where Comment_content LIKE CONCAT('%',#{keyword},'%') and Comment_status = #{Comment_status}")
    List<UserCommentOrder> getCommentcontentArankNA(@Param("keyword") String keyword, @Param("Comment_status") String Comment_status);

    @Select("SELECT c.*,u.Nick_name,o.Product_id,o.order_time,o.Order_status FROM comment c JOIN user u ON c.School_degree = u.School_degree JOIN orders o ON c.order_id = o.order_id where Comment_content LIKE CONCAT('%',#{keyword},'%')")
    List<UserCommentOrder> getCommentcontent(@Param("keyword") String keyword);

    @Select("SELECT c.*,u.Nick_name,o.Product_id,o.order_time,o.Order_status FROM comment c JOIN user u ON c.School_degree = u.School_degree JOIN orders o ON c.order_id = o.order_id where Comment_rank = #{Comment_rank}")
    List<UserCommentOrder> getCommentrank(@Param("Comment_rank") String Comment_rank);

    @Select("SELECT DISTINCT * \n" +
            "FROM comment c \n" +
            "INNER JOIN orders o ON c.order_id = o.order_id\n" +
            "INNER JOIN products p ON o.Product_id = p.Product_id\n" +
            "INNER JOIN user u ON u.School_degree = o.School_degree\n" +
            "WHERE p.School_degree = #{School_degree}\n" +
            "AND c.Comment_status = '通过'\n" +
            "ORDER BY c.Comment_time DESC;")
    List<UserOrderCommentOrder> getMaijiaPingjia(String School_degree);

    @Insert("INSERT INTO comment(School_degree, Comment_content, Comment_rank, order_id, Comment_status) " +
            "VALUES(#{School_degree}, #{Comment_content}, #{Comment_rank}, #{order_id}, '审核中')")
    Integer insertCommentInfoByOrderId(commentInfo commentinfo);

}
